/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = '';
  
  checkConfig(config);
  @endpoint = getEndpoint('nbftestpop', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model TestApiRequest {
  name?: string(name='name'),
}

model TestApiResponseBody = {
  bizException?: boolean(name='bizException'),
  current?: int32(name='current'),
  errorCode?: string(name='errorCode'),
  errorMsg?: string(name='errorMsg'),
  pageSize?: int32(name='pageSize'),
  requestId?: string(name='requestId'),
  result?: string(name='result'),
  success?: boolean(name='success'),
  total?: long(name='total'),
  totalPage?: int32(name='totalPage'),
}

model TestApiResponse = {
  headers: map[string]string(name='headers'),
  body: TestApiResponseBody(name='body'),
}

async function testApi(request: TestApiRequest): TestApiResponse {
  var runtime = new Util.RuntimeOptions{};
  var headers : map[string]string = {};
  return testApiWithOptions(request, headers, runtime);
}

async function testApiWithOptions(request: TestApiRequest, headers: map[string]string, runtime: Util.RuntimeOptions): TestApiResponse {
  Util.validateModel(request);
  var body : map[string]any= {};
  if (!Util.isUnset(request.name)) {
    body['name'] = request.name;
  }

  var req = new OpenApi.OpenApiRequest{ 
    headers = headers,
    body = OpenApiUtil.parseToMap(body),
  };
  var params = new OpenApi.Params{
    action = 'TestApi',
    version = 'tb_test11_0_0',
    protocol = 'HTTPS',
    pathname = `/tb_test1/1_0_0/testApi`,
    method = 'POST',
    authType = 'AK',
    style = 'ROA',
    reqBodyType = 'json',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

